package com.example.ttt;

import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Method;

@SpringBootApplication
public class TttApplication {

    public static void main(String[] args) {
        /*
        * ConfigurableApplicationContext run = SpringApplication.run(TttApplication.class, args);
        * Object startMain = run.getBeanFactory().getBean("startMain");
        * Method start = ReflectionUtils.findMethod(startMain.getClass(), "start");
        * ReflectionUtils.invokeMethod(start,startMain);
        * */


        SpringApplicationBuilder run = new SpringApplicationBuilder(TttApplication.class);
        run.headless(false).web(WebApplicationType.NONE).run(args);

        // 获取springboot的bean
        Object startMain = run.context().getBeanFactory().getBean("startMain");
        // 利用反射执行自己的方法
        Method start = ReflectionUtils.findMethod(startMain.getClass(), "start");
        ReflectionUtils.invokeMethod(start,startMain);
    }

}
